package org.zoomdev.zoom.web.action;

import org.zoomdev.zoom.common.filter.MethodFilter;

import java.lang.reflect.Method;

public interface ActionInterceptorFactory {

    State<PreParseInterceptor> PRE_PARSE = new State<>(PreParseInterceptor.class);
    State<ParseInterceptor> PARSE = new State<>(ParseInterceptor.class);
    State<ResultInterceptor> RESULT = new State<>(ResultInterceptor.class);
    State<ErrorInterceptor> ERROR = new State<>(ErrorInterceptor.class);
    State<CompleteInterceptor> COMPLETE = new State<>(CompleteInterceptor.class);

    State<BeforeInvokeInterceptor> BEFORE_INVOKE = new State<>(BeforeInvokeInterceptor.class);

    /**
     * 注册interception
     *
     * @param interceptor
     * @param pattern     类、方法过滤，形式{@code *} {@code *#*} {@code com.xx.*#*Test} {@link org.zoomdev.zoom.common.filter.MethodFilter }
     */
    void add(ActionInterceptor interceptor, String pattern, int order);

    /**
     * 根据阶段增加 切面
     *
     * @param state
     * @param interceptor
     * @param pattern
     * @param order
     */
    <T> void add(State<T> state, T interceptor, String pattern, int order);

    /**
     * @param interceptor
     * @param filter
     * @param order
     */
    void add(ActionInterceptor interceptor, MethodFilter filter, int order);


    <T> void add(State<T> state, T interceptor, MethodFilter pattern, int order);


    <T> T[] create(State<T> state, Class<?> controllerClass, Method method);

    final class State<T> {
        final Class<T> type;

        private State(Class<T> type) {
            this.type = type;
        }

        public Class<T> type() {
            return type;
        }

    }

}
